package de.tu_darmstadt.informatik.tk.lernsystem.util;

import java.security.MessageDigest;

/**
 * Helper class for generating MD5 hashes from input strings.
 */
public class Md5 {
	public static String getHash(String input) {
		try {
		MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.reset();
        md5.update(input.getBytes());
        byte[] result = md5.digest();
        
        StringBuffer hexString = new StringBuffer();
        for (int i=0; i<result.length; i++) {
        	if(result[i] <= 15 && result[i] >= 0){
        		hexString.append("0");
        	}
        	hexString.append(Integer.toHexString(0xFF & result[i]));
        }
        return hexString.toString();
        
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "";
	}
}
